package com.demo.controller;

import com.demo.R;
import org.miniframework.core.annotation.Controller;
import org.miniframework.mvc.annotation.RequestMapping;
import org.miniframework.mvc.annotation.RequestParam;
import org.miniframework.mvc.annotation.ResponseBody;
import org.miniframework.mvc.type.ModelAndView;
import org.miniframework.mvc.type.RequestMethod;

@Controller
@RequestMapping("/mvc/test")
public class MvcController {

    @RequestMapping(value = "/path",method = RequestMethod.GET)
    public void test(){
        System.out.println("我执行了，无参路径测试");
    }

    @RequestMapping(value = "/path/param",method = RequestMethod.GET)
    @ResponseBody
    public String test2(@RequestParam("id") Integer id){
        return "我执行了，有参路径测试：id => " + id;
    }

    @RequestMapping(value = "/exception",method = RequestMethod.GET)
    public void exception(){
        throw new RuntimeException("抛出异常测试");
    }

    @RequestMapping(value = "/json",method = RequestMethod.GET)
    @ResponseBody
    public R<String> json(){
        return R.ok("json返回测试");
    }

    @RequestMapping(value = "/model",method = RequestMethod.GET)
    public ModelAndView model(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView("model");
        modelAndView.addViewData("name","xiaochi");
        return modelAndView;
    }

    @RequestMapping(value = "/model2",method = RequestMethod.GET)
    public String model2(){
        return "model";
    }
}
